package org.wisdom.ac.domain.role.entity;

import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.wisdom.data.jpa.annotation.SerialNumber;
import org.wisdom.data.jpa.entity.BaseEntity;

import javax.persistence.*;
import java.util.List;

/**
 * 系统角色
 *
 * @author 张智研
 * @date 2022/05/23 15:07
 **/
@SuppressWarnings("JpaDataSourceORMInspection")
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@Slf4j
@NamedEntityGraph(name = "roleWithResource",
        attributeNodes = {@NamedAttributeNode(value = "roleResources")})
public class AcRole extends BaseEntity {

    /** 角色编码 */
    @Column(nullable = false, unique = true)
    @SerialNumber(key = "{t}", value = "R{n}", numberLength = 6)
    @Order(1)
    private String code;

    /** 角色名称 */
    @Column(nullable = false, unique = true)
    @Order(2)
    private String name;

    /** 角色是否可用 */
    @Column(nullable = false)
    @Order(3)
    private Boolean enabled;

    /** 数据权限范围 */
    @Order(4)
    private String dataScope;

    /** 描述 */
    @Order(5)
    private String remark;

    /** 角色拥有的资源 */
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "roleId")
    private List<AcRoleResource> roleResources;



}
